package avicit.bdp.dds.dao.mapper;

import avicit.bdp.common.base.BaseDAO;
import avicit.bdp.dds.dispatch.enums.ExecutionStatus;
import avicit.bdp.dds.dao.entity.ExecuteStatusCount;
import avicit.bdp.dds.dao.entity.TaskInstance;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * task instance mapper interface
 */
public interface TaskInstanceMapper extends BaseDAO<TaskInstance> {

    List<String> queryTaskByProcessIdAndState(@Param("processInstanceId") String processInstanceId,
                                              @Param("state") Integer state);

    List<TaskInstance> findValidTaskListByProcessId(@Param("processInstanceId") String processInstanceId,
                                                    @Param("flag") Integer flag);

    List<TaskInstance> queryByHostAndStatus(@Param("host") String host, @Param("states") int[] stateArray);

    int setFailoverByHostAndStateArray(@Param("host") String host,
                                       @Param("states") int[] stateArray,
                                       @Param("destStatus") ExecutionStatus destStatus);

    TaskInstance queryByInstanceIdAndName(@Param("processInstanceId") String processInstanceId,
                                          @Param("name") String name);

    Integer countTask(@Param("projectIds") Integer[] projectIds, @Param("taskIds") String[] taskIds);

    List<ExecuteStatusCount> countTaskInstanceStateByUser(@Param("startTime") Date startTime,
                                                          @Param("endTime") Date endTime,
                                                          @Param("projectIds") Integer[] projectIds);

    Page<TaskInstance> queryTaskInstanceListPaging(@Param("projectId") String projectId,
                                                   @Param("processInstanceId") String processInstanceId,
                                                   @Param("searchVal") String searchVal,
                                                   @Param("taskName") String taskName,
                                                   @Param("executorId") String executorId,
                                                   @Param("states") int[] statusArray,
                                                   @Param("host") String host,
                                                   @Param("startTime") Date startTime,
                                                   @Param("endTime") Date endTime
    );

    String queryLogIdByProcessInstanceId(@Param("processInstanceId") String processInstanceId);

    Long selectAllNoteCount(@Param("processDefinitionId") String processDefinitionId,
                            @Param("processInstanceId") String processInstanceId);

    Long selectSuccessCount(@Param("processDefinitionId") String processDefinitionId,
                            @Param("processInstanceId") String processInstanceId);

    List<TaskInstance> selectListByInstanceId(@Param("processDefinitionId") String processDefinitionId,
                                              @Param("processInstanceId") String processInstanceId,
                                              @Param("state") Integer state,
                                              @Param("nodeType") Integer nodeType);

    Long getDataCount(@Param("today") String today,
                      @Param("projectIdList") List<String> projectIdList,
                      @Param("state") Integer state);

    Long getSlowCount(@Param("today") String today,
                      @Param("projectIdList") List<String> projectIdList,
                      @Param("state") Integer state,
                      @Param("slowTime") Long slowTime);

    Long getDataCountByProjectId(@Param("today") String today,
                                 @Param("projectId") String projectId,
                                 @Param("state") Integer state);

    Long getSlowCountByProjectId(@Param("today") String today,
                                 @Param("projectId") String projectId,
                                 @Param("state") Integer state,
                                 @Param("slowTime") Long slowTime);

    List<TaskInstance> getFlowTaskProcessByInstanceId(@Param("instanceId") String instanceId);

    void updateTaskAppIdByProcessInstanceId(@Param("processInstanceId") String processInstanceId,
                                            @Param("appId") String appId);

    Map<String, Object> getTaskStateCount(@Param("processInstanceId") String processInstanceId);

    List<Map<String, Object>> getFlowTaskStateCount(@Param("runningIdList")List<String> runningIdList);
}
